<template>
	<view class="richText">
		<tui-navigation-bar :titleSize="18" :titleLineHeight="18" :titlefontWeight="800" :isOpacity="false"
			@init="initNavigation" :title="isTitle" backgroundColor="#fff" color="#000">
			<view class="tui-header-icon" :style="{ marginTop: top + 'px' }">
				<tui-icon name="arrowleft" color="#333" @click="back"></tui-icon>
			</view>
		</tui-navigation-bar>
		<view :style="{ marginTop: marginTp + 'px' }">
			<uParse :content="htmlRichText" />
		</view>
	</view>
</template>

<script>
	import {
		getAgreement
	} from "@/http/api/user/user.js"
	import marked from '@/components/uni/marked'
	import uParse from '@/components/uni/uParse/src/wxParse'
	export default {
		data() {
			return {
				top: 0, //标题图标距离顶部距离
				marginTp: 0,
				htmlRichText: '', //富文本内容 
				type: 1,
			}
		},
		components: {
			uParse
		},
		onLoad(options) {
			console.log(options, 'options')
			this.type = options.type
			this.getAgreementText()
		},
		computed: {
			isTitle() {
				if (this.type == 1) {
					return '用户协议'
				} else if (this.type == 2) {
					return '隐私协议'
				} else if (this.type == 3) {
					return '下单须知'
				} else if (this.type == 4) {
					return '计费规则'
				} else if (this.type == 5) {
					return '关于平台'
				}
			}
		},
		methods: {
			initNavigation(e) {
				this.top = e.top;
				this.marginTp = e.height
			},
			back() {
				uni.navigateBack({
					delta: 1
				});
			},
			getAgreementText() {
				getAgreement(this.type).then(res => {
					console.log(res)
					if (res.code == 200) {
						
						this.htmlRichText = res.data && res.data.protocolContent || ''
					} else {
						self.$utils.toast(res.msg);
					}
				}).catch(err=>{
					console.log('err',err)
				});
			}
		}
	}
</script>

<style scoped>
	@import './richText.css';
</style>